package com.cargohu.aishouyu.app;

import com.cargohu.aishouyu.common.CommonConstants;
import com.cargohu.aishouyu.common.enums.OsPlatformType;
import com.cargohu.aishouyu.framework.response.ApiResult;
import com.cargohu.aishouyu.operation.resp.AppNoticeDetailVo;
import com.cargohu.aishouyu.operation.resp.AppVersionDetailVo;
import com.cargohu.aishouyu.operation.service.AppNoticeService;
import com.cargohu.aishouyu.operation.service.AppVersionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP信息接口
 * </p>
 *
 * @author SuperWein
 * @since 2023/12/2 17:36
 */
@Slf4j
@RestController
@RequestMapping(CommonConstants.API_APP_PATH+"/info")
@Tag(name = "APP信息接口(移动端)")
public class AppInfoController {

    @Autowired
    private AppNoticeService appNoticeService;
    @Autowired
    private AppVersionService appVersionService;

    /**
     * APP最新公告
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/notice")
    @Operation(summary = "APP最新公告")
    public ApiResult<AppNoticeDetailVo> getAppNotice() throws Exception {
        AppNoticeDetailVo appNoticeDetailVo = appNoticeService.getLatestAppNotice();
        return ApiResult.success(appNoticeDetailVo);
    }

    /**
     * 安卓APP最新版本信息
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/android/version")
    @Operation(summary = "安卓APP最新版本信息")
    public ApiResult<AppVersionDetailVo> getAndroidAppVersion() throws Exception {
        AppVersionDetailVo appVersionDetailVo = appVersionService
                .getLatestAppVersion(OsPlatformType.ANDROID.getCode());
        return ApiResult.success(appVersionDetailVo);
    }

    /**
     * 苹果APP最新版本信息
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/ios/version")
    @Operation(summary = "苹果APP最新版本信息")
    public ApiResult<AppVersionDetailVo> getIosAppVersion() throws Exception {
        AppVersionDetailVo appVersionDetailVo = appVersionService
                .getLatestAppVersion(OsPlatformType.IOS.getCode());
        return ApiResult.success(appVersionDetailVo);
    }

}
